﻿@model BBICMS.Application.InputModels.Articles.PostIM

@{
    ViewBag.Title = "添加新闻";
    ViewBag.PageTitle = ViewBag.Title + "_内容";
}
@section Header{
    <link href="~/plugins/SigFinder/SigFinder.min.css" rel="stylesheet" />
    <link href="~/plugins/webuploader/webuploader.css" rel="stylesheet" />
    <link href="~/plugins/datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
}


@using (Ajax.BeginForm("AddPost", null, new AjaxOptions()
{
    HttpMethod = "POST",
    OnBegin = "onBeginSave",
    OnComplete = "onCompleteSave",
    OnSuccess = "updateSuccess"

}, new { @class = "form-horizontal", role = "form" }))
{

    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <div class="panel panel-default">
        <header class="panel-heading">
            <span class="glyphicon glyphicon-edit"></span> @ViewBag.Title

        </header>

        <section class="panel-body">



            <div class="form-group">
                @Html.LabelFor(model => model.Title, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.TextBoxFor(model => model.Title, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Title, ViewData).Watermark })
                    @Html.ValidationMessageFor(model => model.Title)
                </div>

            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.BlogId, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.DropDownListFor(model => model.BlogId, (SelectList)ViewBag.Categories, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.BlogId, ViewData).Watermark })
                    @Html.ValidationMessageFor(model => model.BlogId)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Lang, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.DropDownListFor(model => model.Lang, (SelectList)ViewBag.Langs, new { @class = "form-control", placeholder = Labels.Lang })
                    @Html.ValidationMessageFor(model => model.Lang)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Thumbnail, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    <div class="input-group">
                        @Html.TextBoxFor(model => model.Thumbnail, new { @class = "form-control", placeholder = "图标" })
                        <span class="input-group-btn">
                            <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                        </span>
                    </div><!-- /input-group -->
                </div>
                <div class="col-md-5">
                    @Html.ValidationMessageFor(model => model.Thumbnail)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Body, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.Body, new { placeholder = "内容" })
                    @Html.ValidationMessageFor(model => model.Body)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Summary, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextAreaFor(model => model.Summary, new { @class = "form-control" })

                    @Html.ValidationMessageFor(model => model.Summary)
                </div>
            </div>


            <div class="form-group">
                @Html.LabelFor(model => model.Author, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    @Html.TextBoxFor(model => model.Author, new { @class = "form-control" })
                </div>
                <div class="col-md-2">
                    @Html.ValidationMessageFor(model => model.Author)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Pubdate, new { @class = "col-md-2 control-label" })
                <div class="col-md-10">
                    <div class='input-group date' id='datetimepicker2'>
                        @Html.TextBoxFor(model => model.Pubdate, new { @class = "form-control", placeholder = Labels.Pubdate })
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>
                    @Html.ValidationMessageFor(model => model.Pubdate)
                </div>
            </div>


            <div class="form-group">
                <div class="col-md-10 col-md-offset-2">
                    <div class="checkbox">
                        <label>
                            @Html.CheckBoxFor(model => model.Active)  @Html.DisplayNameFor(model => model.Active)  @Html.ValidationMessageFor(model => model.Active)
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-md-10 col-md-offset-2">
                    <div class="checkbox">
                        <label>
                            @Html.CheckBoxFor(model => model.Recommend)  @Html.DisplayNameFor(model => model.Recommend)  @Html.ValidationMessageFor(model => model.Recommend)
                        </label>
                    </div>
                </div>
            </div>
            <hr />

            <div class="form-group">
                @Html.LabelFor(model => model.Keywords, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.TextBoxFor(model => model.Keywords, new { @class = "form-control", placeholder = "关键字(SEO)" })
                </div>
                <div class="col-md-5">
                    @Html.ValidationMessageFor(model => model.Keywords)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Description, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.TextAreaFor(model => model.Description, new { @class = "form-control", placeholder = "描述(SEO)" })
                </div>
                <div class="col-md-5">
                    @Html.ValidationMessageFor(model => model.Description)
                </div>
            </div>


        </section>
        <footer class="panel-footer text-center">
            <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Add </button>
            <a href="@Url.Action("Index")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> 返回</a>
        </footer>

    </div>

}

@Html.Action("PopuFinder", "File")
@section Footer {
    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")
    <script src="/Plugins/webuploader/webuploader.min.js"></script>
    <script src="/Plugins/SigFinder/FileManager.js"></script>

    <script src="~/plugins/ueditor/ueditor.config.js"></script>
    <script src="~/plugins/ueditor/ueditor.all.min.js"></script>

    <script src="~/Scripts/moment.min.js"></script>
    <script src="~/Scripts/moment-with-locales.min.js"></script>
    <script src="~/plugins/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>

    <!-- 实例化编辑器 -->
    <script type="text/javascript">
    var ue = UE.getEditor('Body');


        function SetThumbnail() {
            var fileUrl = $("#fileList .item.active").attr("data-file");
            $('#Thumbnail').val(fileUrl);
            $('#fileManagerModal').modal('hide');
        }



        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");
        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
        }


    function updateSuccess(data) {
        var title = '@ViewBag.Title';
        Common.ShowBox(data.Status, data.Message, title);
    }



    $(function () {
        $("#btnThumbnail").on("click", function () {
            $('#fileManagerModal').modal();
            $("#selectImage").unbind('click');
            $("#selectImage").bind("click", function () {
                SetThumbnail();
            });
        });

        $('#datetimepicker2').datetimepicker({
            locale: 'zh-CN',
            format: 'L'
        });
        });
    </script>
}
